import type { ColProps } from "ant-design-vue/es/col";
import type { RowProps } from "ant-design-vue/es/row";


export type FormSize = "small" | "middle";

export interface FilterFormSize {
  size: FormSize;
}

type RetLayout = {
  className: string,
  spans: ColProps
};

export interface SizeOpts {
  labelStaticWidth: string;
  gridLayout: ColProps;
  computeLengthToPos: (n?: number) => RowProps["justify"];
  getOperationPos: (size: FormSize, n?: number) => RetLayout;
}

export const sizeMapOption: Record<FormSize, SizeOpts> = {
  small: {
    labelStaticWidth: "135px",
    gridLayout: {
      lg: 12,
      xl: 6,
      span: 12,
      xxxl: 4,
      xxl: 7,
    },
    computeLengthToPos(n) {
      let rowJustity = "space-between" as RowProps["justify"];

      switch (n) {
        case 1:
        case 2:
        case 3:
          rowJustity = "start";
          break;
        case 4:
          rowJustity = "end";
          break;
        default:
          break;
      }
      return rowJustity;
    },

    getOperationPos(size: FormSize, n?: number) {
      const layout: RetLayout = {
        className: "justify-end",
        spans: {
          span: 8
        }
      };
      n;
      if (size === "small") {
        layout.className = "justify-end";
        layout.spans = ({
          span: 3 + (n ? 2 * n : 0),
        } as ColProps);
      }
      return layout as RetLayout;
    }
  },
  middle: {
    labelStaticWidth: "120px",
    gridLayout: {
      lg: 12,
      xl: 8,
      span: 12,
      xxxl: 4,
      xxl: 8,
    },

    getOperationPos(size: FormSize, n?: number) {
      const layout: RetLayout = {
        className: "justify-end",
        spans: {
          span: 8
        }
      };
      n;
      if (size === "middle") {
        layout.className = "justify-start";
        layout.spans = ({
          lg: 12,
          xl: 8,
          span: 12,
          xxxl: 4,
          xxl: 8,
          push: 2
        } as ColProps);
      }

      return layout as RetLayout;
    },
    computeLengthToPos(n) {
      let rowJustity = "space-between" as RowProps["justify"];

      switch (n) {
        case 1:
        case 2:
        case 3:
          rowJustity = "start";
          break;
        case 4:
          rowJustity = "end";
          break;
        default:
          break;
      }
      return rowJustity;
    }
  }
};
